package oicon;

import java.awt.*;
import java.awt.print.*;

public class SimplePrint2D implements Printable {
	private static Font fnt = new Font("Helvetica", Font.PLAIN, 24);
	private Paint pnt = new GradientPaint(100f, 100f, Color.red, 136f, 100f,
			Color.green, true);

	public static void main(String[] args) {
		// Get a PrinterJob
		PrinterJob job = PrinterJob.getPrinterJob();
		// Specify the Printable is an instance of SimplePrint2D
		job.setPrintable(new SimplePrint2D());
		// Put up the dialog box
		if (job.printDialog()) {
			// Print the job if the user didn't cancel printing
			try {
				job.print();
			} catch (Exception e) { /* handle exception */
			}
		}
		System.exit(0);
	}

	public int print(Graphics g, PageFormat pf, int pageIndex)
			throws PrinterException {
		// pageIndex 0 to 4 corresponds to page numbers 1 to 5.
		if (pageIndex >= 5)
			return Printable.NO_SUCH_PAGE;
		Graphics2D g2 = (Graphics2D) g;
		// Use the font defined above
		g2.setFont(fnt);
		// Use the gradient color defined above
		g2.setPaint(pnt);
		g2.drawString("Page " + (pageIndex + 1), 100f, 100f);
		return Printable.PAGE_EXISTS;
	}

}
